package w.w2;

import java.util.Stack;

//用栈来实现队列
class MyQueueUsStack{
    public Stack<Integer> stack1= new Stack<>();
    public Stack<Integer> stack2= new Stack<>();


    public boolean Empty(){
        return stack1.empty()&&stack2.empty();
    }
    public void push(int x){
        stack1.push(x);

    }
    public int pop(){
        if (Empty()){
            return -1;
        }
        if (stack2.empty()){
           while (!stack1.isEmpty()){
               stack2.push(stack1.pop());
           }

        }
         return stack2.pop();
    }
    public int peek(){
        if (Empty()){
            return -1;
        }
        if (stack2.empty()){
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }

        }
        return stack2.peek();
    }
}
public class Text {
    public static void main(String[] args) {
        MyQueueUsStack myQueueUsStack=new MyQueueUsStack();
        myQueueUsStack.push(1);
        myQueueUsStack.push(2);
        myQueueUsStack.push(3);
        myQueueUsStack.push(4);
        System.out.println(myQueueUsStack.pop());
        System.out.println(myQueueUsStack.pop());

    }
}
